#!/bin/sh

# 19.11.2006 Volker Quetschke
# Check that a global .SEQUENTIAL attribute enforces MAXPROCESS=1.
# (issue 71704)

: ${DMAKEPROG:=dmake}
file1="mfile1.mk"
file2="my.inc"
tmpfiles="$file1 $file2"

trap '{ echo "trapped signal - removing temporary files" ; rm -rf $tmpfiles ; }' 1 2 3 15

# Remove files from prior failed run
rm -rf $tmpfiles

# Remember to quote variables in generated makefiles( $ -> \$ ).
cat > $file1 <<EOT
SHELL=/bin/sh
SHELLFLAGS=-c

my.inc :
	@+echo "MYMAXPROCESS!:=\$(MAXPROCESS)" > my.inc

.INCLUDE : my.inc

all:
	@+echo "MYMAXPROCESS:\$(MYMAXPROCESS):"

EOT

output=`eval ${DMAKEPROG} -S -P2 -rf $file1 all`
result=$?

if test "$output" != "MYMAXPROCESS:1:"; then
  echo "Wrong result: $output - expecting: MYMAXPROCESS:1:"
  result=1
fi 
 
test $result -eq 0 && echo "Success - Cleaning up" && rm -f ${tmpfiles}
test $result -ne 0 && echo "Failure!"
exit $result
